﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLHD.Entity.Manipulation;

namespace QLHD.DAL.Manipulation
{
    public class DanhMuc_DAL
    {
        const string spDanhMucHopDong_ListAll = "sp_DanhMucHopDong_SelectAll";
        const string spDanhMucNhanSu_ListAll = "sp_NhanSu_SelectAll";
        const string sp_KhachHang_SelectAll = "sp_KhachHang_SelectAll";
        const string sp_NhanHang_SelectAll = "sp_NhanHang_SelectAll";
        const string sp_NhomNganh_GetByNhanHang = "sp_NhomNganh_GetByNhanHang";
        const string sp_HinhThucQuangCao_SelectAll = "sp_HinhThucQuangCao_SelectAll";
        const string sp_SanPham_GetByHinhThucQuangCao = "sp_SanPham_GetByHinhThucQuangCao";
        const string sp_DonViSanPham_GetBySanPham = "sp_DonViSanPham_GetBySanPham";
        const string sp_Website_SelectAll = "sp_Website_SelectAll";
        const string sp_ChuyenMuc_SelectAll = "sp_ChuyenMuc_SelectAll";
        const string sp_Banner_SelectAll = "sp_Banner_SelectAll";
        const string sp_Tag_SelectAll = "sp_Tag_SelectAll";
        const string sp_TaiKhoanAdmk_SelectAll = "sp_TaiKhoanAdmk_SelectAll";
        const string sp_BaoGiaHopDong_FilterToGetDonGia = "sp_BaoGiaHopDong_FilterToGetDonGia";

        public static List<DanhMuc.DanhMucHopDong> DanhMucHopDong_ListAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.DanhMucHopDong>(DbCommon.GetConnection(), spDanhMucHopDong_ListAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", spDanhMucHopDong_ListAll, ex.Message));
            }
        }

        public static List<DanhMuc.DanhMucNhanSu> DanhMucNhanSu_ListAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.DanhMucNhanSu>(DbCommon.GetConnection(), spDanhMucNhanSu_ListAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", spDanhMucNhanSu_ListAll, ex.Message));
            }
        }

        public static List<DanhMuc.DanhMucKhachHang> DanhMucKhachHang_ListAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.DanhMucKhachHang>(DbCommon.GetConnection(), sp_KhachHang_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_KhachHang_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.DanhMucNhanHang> DanhMucNhanHang_ListAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.DanhMucNhanHang>(DbCommon.GetConnection(), sp_NhanHang_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_NhanHang_SelectAll, ex.Message));
            }
        }

        public static DanhMuc.DanhMucNhomNganh NhomNganh_GetByNhanHang(long NhanHangID)
        {
            try
            {
                var parameters = new[] { new SqlParameter("@NhanHangID", NhanHangID) };
                return DbCommon.ExecuteSingle<DanhMuc.DanhMucNhomNganh>(DbCommon.GetConnection(), sp_NhomNganh_GetByNhanHang, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_NhomNganh_GetByNhanHang, ex.Message));
            }
        }

        public static List<DanhMuc.HinhThucQuangCao> HinhThucQuangCao_ListAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.HinhThucQuangCao>(DbCommon.GetConnection(), sp_HinhThucQuangCao_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_HinhThucQuangCao_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.SanPham> SanPham_GetByHinhThucQuangCao(string HinhThucQuangCaoID)
        {
            try
            {
                var parameters = new[] { new SqlParameter("@HinhThucQuangCaoID", HinhThucQuangCaoID) };
                return DbCommon.ExecuteList<DanhMuc.SanPham>(DbCommon.GetConnection(), sp_SanPham_GetByHinhThucQuangCao, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_SanPham_GetByHinhThucQuangCao, ex.Message));
            }
        }

        public static List<DanhMuc.DonViTinh> DonViTinh_GetBySanPham(long sanphamID)
        {
            try
            {
                var parameters = new[] { new SqlParameter("@SanPhamID", sanphamID) };
                return DbCommon.ExecuteList<DanhMuc.DonViTinh>(DbCommon.GetConnection(), sp_DonViSanPham_GetBySanPham, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_DonViSanPham_GetBySanPham, ex.Message));
            }
        }
        public static List<DanhMuc.Website> Website_SelectAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.Website>(DbCommon.GetConnection(), sp_Website_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_Website_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.ChuyenMuc> ChuyenMuc_SelectAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.ChuyenMuc>(DbCommon.GetConnection(), sp_ChuyenMuc_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_ChuyenMuc_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.Banner> Banner_SelectAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.Banner>(DbCommon.GetConnection(), sp_Banner_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_Banner_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.Tag> Tag_SelectAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.Tag>(DbCommon.GetConnection(), sp_Tag_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_Tag_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.TaiKhoanAdmk> TaikhoanAdmk_SelectAll()
        {
            try
            {
                return DbCommon.ExecuteList<DanhMuc.TaiKhoanAdmk>(DbCommon.GetConnection(), sp_TaiKhoanAdmk_SelectAll);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_TaiKhoanAdmk_SelectAll, ex.Message));
            }
        }

        public static List<DanhMuc.BaoGiaHopDong> BaoGiaHopDong_FilterDonGia(string hinhthucquangcaoID, string SanPhamID, string donvitinh, string TagID, string WebsiteID, string ChuyenMucID, string BannerID)
        {
            try
            {
                var parameters = new[] { 
                                        new SqlParameter("@HinhThucQuangCaoID", hinhthucquangcaoID),
                                        new SqlParameter("@SanPhamID", SanPhamID),
                                        new SqlParameter("@DonViTinhID", donvitinh),
                                        new SqlParameter("@TagID", TagID),
                                        new SqlParameter("@WebsiteID", WebsiteID),
                                        new SqlParameter("@ChuyenMucID", ChuyenMucID),
                                        new SqlParameter("@BannerID", BannerID),
                                        };
                return DbCommon.ExecuteList<DanhMuc.BaoGiaHopDong>(DbCommon.GetConnection(), sp_BaoGiaHopDong_FilterToGetDonGia, parameters);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0}:: {1}", sp_BaoGiaHopDong_FilterToGetDonGia, ex.Message));
            }
        }
    }
}
